const db_manager = require(__dirname + '/../lib/db_manager');

const db = db_manager.load_db(process.env.ZETHER_DATADIR);
const state = db.getState();

function only_last(o, key) {
  const a = o[key];
  if (a.length > 0) {
    o[key] = [a[a.length - 1]];
  }
}

only_last(state, 'inner-product-verifiers');
only_last(state, 'burn-verifiers');
only_last(state, 'transfer-verifier-inners');
only_last(state, 'transfer-verifiers');

const zethers = state['zethers'];
const values = Object.values(zethers);
if (values.length > 0) {
  const zether = values[values.length - 1];
  state['zethers'] = {
    [zether.contractAddress]: zether
  };
}

db.setState(state).write();
